package cn.edu.zut.internship.web.controller.notify;

import cn.edu.zut.internship.bean.sys.Result;
import cn.edu.zut.internship.bean.sys.SysUser;
import cn.edu.zut.internship.iservice.notify.NotifySV;
import cn.edu.zut.internship.web.utils.UserInfoUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
@RestController
@RequestMapping("/notify")
public class NotifyController {
    @Reference
    NotifySV notifySV;

    /**
     * 消息列表查询
     * @param params
     * @return
     */
    @RequestMapping("/getNotifyList")
    public Result getNotifyList(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        params.put("targetAccount",userInfo.getUserAccount());
        result = notifySV.selectNotify(params);
        return result;
    }

    /**
     * 查看消息详情
     * @param params
     * @return
     */
    @RequestMapping("/getNotify")
    public Result getNotify(@RequestBody Map params) {
        Result result = new Result();
        Long notifyId = Long.valueOf((String) params.get("notifyId"));
        result = notifySV.getNotifyById(notifyId);
        return result;
    }

    /**
     * 新增消息
     * @param params
     * @return
     */
    @RequestMapping("/addNotify")
    public Result addNotify(@RequestBody Map params) {
        Result result = new Result();
        result = notifySV.addNotify(params);
        return result;
    }

    /**
     * 更新消息
     * @param params
     * @return
     */
    @RequestMapping("/updateNotify")
    public Result updateNotify(@RequestBody Map params) {
        Result result = new Result();
        result = notifySV.updateNotify(params);
        return result;
    }

    /**
     * 删除消息
     * @param params
     * @return
     */
    @RequestMapping("/deleteNotify")
    public Result deleteNotify(@RequestBody Map params) {
        Result result = new Result();
        Long notifyId = (Long) params.get("notifyId");
        result = notifySV.delectNotify(notifyId);
        return result;
    }

    /**
     * 获取当前登录用户未读消息总数
     * @return
     */
    @RequestMapping("/getNotifyNum")
    public Result getNotifyNum(){
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String userAccount = userInfo.getUserAccount();
        result = notifySV.getNotifyNum(userAccount);
        return result;
    }

    /**
     * 删除当前用户所有消息
     * @return
     */
    @RequestMapping("/deleteAll")
    public Result deleteAll(){
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String userAccount = userInfo.getUserAccount();
        result = notifySV.deleteAll(userAccount);
        return result;
    }

    /**
     * 标记当前 用户所有消息为已读
     * @return
     */
    @RequestMapping("/redAll")
    public Result redAll(){
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String userAccount = userInfo.getUserAccount();
        result = notifySV.redAll(userAccount);
        return result;
    }

    /**
     * 标记一条消息为已读
     * @return
     */
    @RequestMapping("/redNotify")
    public Result redNotify(@RequestBody Map params){
        Result result = new Result();
        result = notifySV.redNotify(params);
        return result;
    }

    /**
     * 提醒管理员审核实训单位
     * @param params
     * @return
     */
    @RequestMapping("/remindAdmin")
    public Result remindAdmin(@RequestBody Map params){
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        params.put("userInfo",userInfo);
        result = notifySV.remindAdmin(params);
        return result;
    }

}
